#ifndef CLEVELRENDERER_H
#define CLEVELRENDERER_H

#include "constantes.h"
#include "ISingleton.h"

class CSDLManager;
class CRenderBackground;
class CRenderPlayer;
class CRenderEnemy;

struct SDL_Surface;

//**************************
//Manage Rendering of the Levels
//**************************
class CLevelRenderer : public ISingleton< CLevelRenderer >
{
    private:
		DECLARE_SINGLETON( CLevelRenderer );

        CSDLManager * m_SDLManager;     //Manager of SDL functions

        short * m_sCurrentLevel;   //Number of the level currently played (diiferent for each player)
                                 //First level is level 0

        long m_lBeginLevel;      //time when the level has begun
        long m_lBeginPause;      //time when a pause (the user press P) occur
        long m_lPauseTime;        //total time when the game has paused

        CRenderBackground * m_Background;	//Background of the current level

        short m_sNbPlayers; //Number of players

        CRenderPlayer * m_vPlayers;	//Tab of players

        short m_sCurrentPlayer; //the player currently in game

        short m_sNbEnemies; //Number of enemies

        CRenderEnemy * m_vEnemies;	//Tab of enemies

        long m_lHighScore;              //High score of the game

        SDL_Surface ** m_Highscores;     //Highscores surface to draw in the game

        SDL_Surface ** m_Lives;     //Lives surface to draw in the game

        SDL_Surface ** m_Numbers;     //Numbers surface to draw in the game

        //**************************
        //Description : Constructor
        //Parameters : None
        //Note : Private because a single instance is needed
        //**************************
        CLevelRenderer();

        //**************************
        //Description : Destructor
        //Parameters : None
        //Note : None
        //**************************
        ~CLevelRenderer();


    public:
        //**************************
        //Description : Init the instance
        //Parameters : None
        //Return Value : None
        //Note : None
        //**************************
        virtual void Init();

        //**************************
        //Description : DeInit the instance
        //Parameters : None
        //Return Value : None
        //Note : None
        //**************************
        virtual void DeInit();

        //**************************
        //Description : Load the level _szLevel
        //Parameters : Pointer toward the current level configuration file
        //Return Value : true if success, otherwise false
        //Note : Have to be called after the SDL initialisation because we need a screen
        //**************************
        bool LoadLevel(const char * _szLevelDir);

        //**************************
        //Description : Load the last game saved
        //Parameters : The path to the game
        //Return Value : true if success, otherwise false
        //Note : Have to be called after the SDL initialisation because we need a screen
        //**************************
        bool LoadGame(const char * _szLoad);

        //**************************
        //Description : Save the current game
        //Parameters : The path to the save
        //Return Value : true if success, otherwise false
        //Note : Have to be called after the SDL initialisation because we need a screen
        //**************************
        bool SaveGame(const char * _szSave);

        //**************************
        //Description : Restart the current level
        //Parameters : None
        //Return Value : None
        //Note : RestartLevel is called when a player die, because we can't restart a level when we want
        //**************************
        void RestartLevel();

        //**************************
        //Description : Load the highscore of the game
        //Parameters : None
        //Return Value : true if success, otherwise false
        //Note : None
        //**************************
        bool LoadHighScore();

        //**************************
        //Description : Save the highscore of the game
        //Parameters : None
        //Return Value : true if success, otherwise false
        //Note : None
        //**************************
        bool SaveHighScore();

        //**************************
        //Description : Return the highscore of the game
        //Parameters : None
        //Return Value : The high score of the game
        //Note : have to be called after LoadHighScore
        //**************************
        long GetHighScore();

        //**************************
        //Description : Start the game from the beginning with _sNbPLayers
        //Parameters : The number of players
        //Return Value : None
        //Note : None
        //**************************
        void StartGame(short _sNbPlayers);

        //**************************
        //Description : Start the game from a save file
        //Parameters : The save configuration file
        //Return Value : None
        //Note : None
        //**************************
        void StartGame(const char * _szLoadLevel);

        //**************************
        //Description : Test if the game is over or not
        //Parameters : None
        //Return Value : True if the game is over, false if not
        //Note : The game is over whan all players don't have life anymore
        //**************************
        bool GameOver();

        //**************************
        //Description : Test if the current level is over or not
        //Parameters : None
        //Return Value : True if the lvel is over, false if not
        //Note : The level is over when all ennemies went out of the screen or are dead
        //**************************
        bool LevelOver();

        //**************************
        //Description : Manage collision between all rendering entities
        //Parameters : None
        //Return Value : True if the players collide with an enemy or a shot, otherwise false
        //Note : None
        //**************************
        bool Collision();

        //**************************
        //Description : Draw the statistics of the given player at the end of a level, of the game or when it's game over
        //Parameters : The number of the player we want to draw the statistics
        //Return Value : None
        //Note : None
        //**************************
        void DrawPlayerStatistics(int _iNumPlayer);

        //**************************
        //Description : Draw the statistics on the screen at the end of the level or at the end of the game
        //Parameters : None
        //Return Value : None
        //Note : None
        //**************************
        void DrawEndStatistics();

        //**************************
        //Description : Draw the statistics on the screen
        //Parameters : None
        //Return Value : None
        //Note : None
        //**************************
        void DrawStatistics();

        //**************************
        //Description : Draw the screen
        //Parameters : None
        //Return Value : None
        //Note : None
        //**************************
        void DrawScene();

        //**************************
        //Description : Manage events in the game
        //Parameters : a boolean, to know if the player quit the game, a boolean to know if we are in pause or not
        //Return Value : None
        //Note : None
        //**************************
        void ManageEvents(bool & _bEndGame, bool & _bPauseGame);

        //**************************
        //Description : Manage the game
        //Parameters : None
        //Return Value : None
        //Note : None
        //**************************
        void Game();
};
#endif
